const documentService = require('../services/documentService');

class DocumentController {
  static async qa(req, res) {
    try {
      const { question, context } = req.body;
      
      if (!question || !context) {
        return res.status(400).json({ error: '问题和上下文内容不能为空' });
      }

      const answer = await documentService.qa(question, context);
      res.json({ answer });
    } catch (error) {
      res.status(500).json({ error: '服务器内部错误' });
    }
  }

  static async summarize(req, res) {
    try {
      const { text } = req.body;
      
      if (!text) {
        return res.status(400).json({ error: '文本内容不能为空' });
      }

      const summary = await documentService.summarize(text);
      res.json({ summary });
    } catch (error) {
      res.status(500).json({ error: '服务器内部错误' });
    }
  }
}

module.exports = DocumentController;